package Store;

public class Item {
	private String itemID = "";
	private String name = "";
	private String ISBN = "";
	private String description = "";
	private Float price = 0.0f;
	private Boolean onSale = false;
	private Float salePrice = 0.0f;
	private Integer quantity = 0;
	private Boolean available = false;
	private String tags[] = {};
	
	public Item(String name, String ISBN, String description, float price, boolean onSale, float salePrice, int quantity, boolean available, String... tags){
		this.setName(name);
		this.setISBN(ISBN);
		this.setDescription(description);
		this.setPrice(price);
		this.setOnSale(onSale);
		this.setSalePrice(salePrice);
		this.setQuantity(quantity);
		this.setAvailable(available);
		this.setTags(tags);
		this.itemID = this.setItemID();
	}
	
	public Item(String name, String ISBN, String description, float price, boolean onSale, float salePrice, int quantity, boolean available){
		this.setName(name);
		this.setISBN(ISBN);
		this.setDescription(description);
		this.setPrice(price);
		this.setOnSale(onSale);
		this.setSalePrice(salePrice);
		this.setQuantity(quantity);
		this.setAvailable(available);
		this.itemID = this.setItemID();
	}

	public Item() {
	}

	private String setItemID() {
		return ISBN;
	}

	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getISBN() {
		return ISBN;
	}
	
	public void setISBN(String iSBN) {
		ISBN = iSBN;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public Float getPrice() {
		return price;
	}
	
	public void setPrice(float price) {
		this.price = price;
	}
	
	public Boolean isOnSale() {
		
		return onSale;
	}
	
	public void setOnSale(boolean onSale) {
		this.onSale = onSale;
	}
	
	public Float getSalePrice() {
		return salePrice;
	}
	
	public void setSalePrice(float salePrice) {
		this.salePrice = salePrice;
	}
	
	public String[] getTags() {
		return tags;
	}
	
	public void setTags(String tags[]) {
		this.tags = tags;
	}

	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	public Boolean isAvailable() {
		return available;
	}

	public void setAvailable(boolean available) {
		this.available = available;
	}

	public void setItemID(String itemID) {
		this.itemID = itemID;
	}

	public String getItemID() {
		return itemID;
	}
	
	public boolean commitItem(){
		try{
			DatabaseAccess accessDatabase = new DatabaseAccess();
			accessDatabase.addItemsToDomain(this);
		}
		catch(Exception E)
		{
			return false;
		}
		return true;
	}
	
	public static Item[] getItem(String itemID){
		Store.Item temp[] = null;
		DatabaseAccess accessDatabase = new DatabaseAccess();
		temp = accessDatabase.getItem(itemID);
		return temp;
	}
	
}
